#!/bin/sh
MAINIP=$(ip route get 1 | awk '{print $NF;exit}')
GATEWAYIP=$(ip route | grep default | awk '{print $3}')
SUBNET=$(ip -o -f inet addr show | awk '/scope global/{sub(/[^.]+\//,"0/",$4);print $4}' | head -1 | awk -F '/' '{print $2}')

value=$(( 0xffffffff ^ ((1 << (32 - $SUBNET)) - 1) ))
NETMASK="$(( (value >> 24) & 0xff )).$(( (value >> 16) & 0xff )).$(( (value >> 8) & 0xff )).$(( value & 0xff ))"

    if [[ -n `command -v apt-get` ]];then
        INSTALL="apt-get install -y xz-utils openssl gawk file wget"
    elif [[ -n `command -v yum` ]]; then
        INSTALL="yum install -y xz openssl gawk file wget"
    else
        return 1
    fi
$INSTALL
wget http://oss.illii.cn/dd/Core_Install.sh
clear
echo "                                                           "
echo "###########################################################"
echo "#                                                         #"
echo "#  莫伤老师二开自动dd一键脚本                            
                    #"
echo "#  重装看机子配置，小机一般几十分钟-几小时不等 耐心等待即可                                                   #"
echo "#  所有系统无特殊说明默认密码：cxthhhhh.com               #"
echo "#  所有系统无特殊说明默认密码：cxthhhhh.com               #"
echo "#  所有系统无特殊说明默认密码：cxthhhhh.com               #"
echo "###########################################################"
echo "                                                           "
echo "IP: $MAINIP"
echo "网关: $GATEWAYIP"
echo "网络掩码: $NETMASK"
echo "                                                            "                                     
echo "请选择您需要的镜像包:"
echo "  1) 一键网络重装纯净CentOS 6"
echo "  2) 一键网络重装纯净CentOS 7（推荐）"
echo "  3) 一键网络重装纯净CentOS 8"
echo "  4) 一键网络重装纯净Debian 7"
echo "  5) 一键网络重装纯净Debian 8"
echo "  6) 一键网络重装纯净Debian 9（推荐）"
echo "  7) 一键网络重装纯净Debian 10"
echo "  8) 一键网络重装纯净Ubuntu 14.04"
echo "  9) 一键网络重装纯净Ubuntu 16.04"
echo "  10) 一键网络重装纯净Ubuntu 18.04（推荐）"
echo "  11) 一键网络重装纯净Windows Server 2003"
echo "  12) 一键网络重装纯净Windows 7"
echo "  13) 一键网络重装纯净Windows 8.1"
echo "  14) 一键网络重装纯净Windows Server 2008 R2"
echo "  15) 一键网络重装纯净Windows Server 2012 R2"
echo "  16)一键网络重装纯净Windows Server 2016"
echo "  17)一键网络重装纯净Windows Server 2019（推荐）"
echo ""
echo -n "请输入编号: "
read N
case $N in
  1) bash Core_Install.sh -c 6.10 -v 64 -a ;;
  2) bash Core_Install.sh -dd 'http://pan.illii.cn/file/5fbdca64f785d904054b8092/6010cc1be9ea5cbfcab04d61bf5dff904d548a16/CentOS_7.X_NetInstallation.vhd.gz' ;;
  3) bash Core_Install.sh -dd 'http://pan.illii.cn/file/5fbdca64f785d904054b8092/6010cc29d1f99cdc405f429397fdac05aa5f1ed1/CentOS_8.X_NetInstallation.vhd.gz' ;;
  4) bash Core_Install.sh -d 7 -v 64 -a ;;
  5) bash Core_Install.sh -d 8 -v 64 -a ;;
  6) bash Core_Install.sh -d 9 -v 64 -a ;;
  7) bash Core_Install.sh -d 10 -v 64 -a ;;
  8) bash Core_Install.sh -u 14.04 -v 64 -a ;;
  9) bash Core_Install.sh -u 16.04 -v 64 -a ;;
  10) bash Core_Install.sh -u 18.04 -v 64 -a ;;
  11) bash Core_Install.sh -dd 'http://pan.illii.cn/file/5fbdca64f785d904054b8092/6010cc33b203444410e44923a37890a5ce21a5bd/Disk_Windows_Server_2003_DataCenter_CN.vhd.gz' ;;
  12) bash Core_Install.sh -dd 'http://pan.illii.cn/file/5fbdca64f785d904054b8092/6010fb5eaf34122d9b9940ddac274efd88e3684b/Disk_Windows_7_Vienna_Ultimate_CN.vhd.gz' ;;
  13) bash Core_Install.sh -dd 'http://pan.illii.cn/file/5fbdca64f785d904054b8092/60110452ab08c3ce997d43a99c4290684555fdaa/win8.1emb_x64.tar.gz' ;;
  14) bash Core_Install.sh -dd 'http://pan.illii.cn/file/5fbdca64f785d904054b8092/6010fb6841c2ab7d96a84a4eb5e054d6680adafd/Disk_Windows_Server_2008R2_DataCenter_CN.vhd.gz' ;;
  15) bash Core_Install.sh -dd 'http://pan.illii.cn/file/5fbdca64f785d904054b8092/6010f4bfcc4e9c447118441aa69ed264209f5d81/Disk_Windows_Server_2012R2_DataCenter_CN.vhd.gz' ;;
  16) bash Core_Install.sh -dd 'http://pan.illii.cn/file/5fbdca64f785d904054b8092/6010fb76625dd27f65784ee6b79216ce4c93514c/Disk_Windows_Server_2016_DataCenter_CN.vhd.gz' ;;
  17) bash Core_Install.sh -dd 'http://pan.illii.cn/file/5fbdca64f785d904054b8092/6010fe1c438be5c275934d3292987d541ed370ce/Disk_Windows_Server_2019_DataCenter_CN.vhd.gz' ;;
  *) echo "输入错误!" ;;
esac